import {
	RouterMount,
	createRouter,
	runtimeQuit
} from 'uni-simple-router';
import store from './store';


const router = createRouter({
	platform: process.env.VUE_APP_PLATFORM,  
	APP:{
		animation:{
			animationType:'slide-in-right',
			animationDuration:300
		}
	},
	routerBeforeEach:(to, from, next) => {
		next();
	},
	routerAfterEach:(to, from) => {
	},
	routerErrorEach:({type,msg})=>{
		console.log({type,msg})
		// #ifdef APP-PLUS
			if(type===3){
				router.$lockStatus=false;
				runtimeQuit();
			}
		// #endif
	},
	routes: [
		...ROUTES,
		{
		  path: '*',
		  redirect:(to)=>{
			  return {name:'404'}
		  }
		},
	]
});
router.beforeEach((to, from, next) => {
	//判断页面是否需要登录标识
	let isNeedLogin = to.meta.needLogin;
	//判断用户是否登录
	let isLogin = store.getters.hasLogin;
	isNeedLogin ? (isLogin ? next(): (function a(){
		uni.showToast({
		    title: '请先登录',
		    duration: 2000
		});
		next({
				name:'login',
            });
	})() ) : next();
	
});
router.afterEach((to, from, next) => {
});

export {
	router,
	RouterMount
}